﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using StructureMap.Pipeline;
using StructureMap;
using Castle.DynamicProxy;

using ProjectBase.Core;

namespace Survey.Tools.IoC
{
    [CLSCompliant(false)]
    public class ProxyInstance : Instance
    {
        protected readonly ProxyGenerator Factory = new ProxyGenerator();
        protected readonly Type ConcreteType;
        protected const string Template = "Proxy will return: {0}";

        public ProxyInstance(Type type)
        {
            ConcreteType = type;
        }
        protected override object build(Type pluginType, BuildSession session)
        {
            var aopFilters = AopFilterManager.GetFilters()
                .Union(new[] { new Wrapper(ConcreteType) })
                .ToArray();
            var proxy = Factory.CreateClassProxy(ConcreteType, AopFilterManager.AopOptions, aopFilters);
            return proxy;
        }

        protected override string getDescription()
        {
            return Template.FormatWith(ConcreteType.FullName);
        }
    }
}
